package com.ymatou.es.testcase;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import net.sf.json.JSONObject;

import org.json.JSONArray;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.es.service.CmbjuyanghuoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;

public class Ts_Cmbjuyanghuo {
	private static CmbjuyanghuoCall jyhCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查看商品索引接口");
	}

	@Before
	public void caseUp() {
		//getinfoBean=new GetinfoBean();
		jyhCall=new CmbjuyanghuoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(jyhCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	
	public void Tc_Cmbjuyanghuo_001() {
		Logger.start(true, "索引能否正常访问");
		try {
			jyhCall.callService();
			
			String timeoutString = jyhCall.getTimeoutStatus();
		    Logger.verifyEquals("false", timeoutString, "接口是否超时");
		    
		    Object hits = jyhCall.getHits();
		    Logger.verifyNotNull(hits, "索引值不为空");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	
	public void Tc_Cmbjuyanghuo_002() {
		Logger.start(true, "索引读取是否为最新版本");
		try {
			jyhCall.callService();
			
			String index = jyhCall.getIndex();
			String s = new String(index);   
	        String a[] = s.split("cmbjuyanghuo");  
	        
	        Date date=new Date();
	        DateFormat format=new SimpleDateFormat("yyyyMMddHH");
	        String time=format.format(date);
	        String ymr = a[1].substring(0,10);
	      
	      Logger.verifyEquals(time, ymr, "返回索引数据是否为同一小时内数据");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}
